home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / checko1a / checkino.frm (.txt) next >
Encoding:
Visual Basic Form  |  1999-09-03  |  29.6 KB  |  745 lines

  1. VERSION 5.00
  2. Begin VB.Form frmCheckInOut 
  3.    Caption         =   "Source Code Check In/Out"
  4.    ClientHeight    =   1995
  5.    ClientLeft      =   60
  6.    ClientTop       =   345
  7.    ClientWidth     =   4680
  8.    LinkTopic       =   "Form1"
  9.    ScaleHeight     =   1995
  10.    ScaleWidth      =   4680
  11.    StartUpPosition =   3  'Windows Default
  12.    Begin VB.CommandButton cmdResolve 
  13.       Height          =   450
  14.       Left            =   3000
  15.       Picture         =   "CheckInOut.frx":0000
  16.       Style           =   1  'Graphical
  17.       TabIndex        =   10
  18.       TabStop         =   0   'False
  19.       ToolTipText     =   "Compare files to resolve conflicts"
  20.       Top             =   850
  21.       Width           =   450
  22.    End
  23.    Begin VB.Timer Timer 
  24.       Interval        =   60000
  25.       Left            =   480
  26.       Top             =   360
  27.    End
  28.    Begin VB.CommandButton cmdOptions 
  29.       Height          =   450
  30.       Left            =   3502
  31.       Picture         =   "CheckInOut.frx":0442
  32.       Style           =   1  'Graphical
  33.       TabIndex        =   9
  34.       TabStop         =   0   'False
  35.       ToolTipText     =   "Change application options"
  36.       Top             =   850
  37.       Width           =   450
  38.    End
  39.    Begin VB.CommandButton cmdNetDir 
  40.       Caption         =   "Net Directory:"
  41.       Height          =   255
  42.       Left            =   50
  43.       TabIndex        =   8
  44.       TabStop         =   0   'False
  45.       ToolTipText     =   "Browse for network directory"
  46.       Top             =   510
  47.       Width           =   1335
  48.    End
  49.    Begin VB.CommandButton cmdLocalDir 
  50.       Caption         =   "Local Directory:"
  51.       Height          =   255
  52.       Left            =   50
  53.       TabIndex        =   7
  54.       TabStop         =   0   'False
  55.       ToolTipText     =   "Browse for local directory"
  56.       Top             =   80
  57.       Width           =   1335
  58.    End
  59.    Begin VB.CommandButton cmdMessage 
  60.       Height          =   450
  61.       Left            =   4000
  62.       Picture         =   "CheckInOut.frx":0884
  63.       Style           =   1  'Graphical
  64.       TabIndex        =   6
  65.       TabStop         =   0   'False
  66.       ToolTipText     =   "Send a message"
  67.       Top             =   850
  68.       Width           =   575
  69.    End
  70.    Begin VB.CommandButton cmdHelp 
  71.       Caption         =   "Help"
  72.       Height          =   495
  73.       Left            =   120
  74.       TabIndex        =   5
  75.       Top             =   1380
  76.       Width           =   1215
  77.    End
  78.    Begin VB.CheckBox chkAutoCheck 
  79.       Caption         =   "Automatically check for file changes"
  80.       Height          =   315
  81.       Left            =   120
  82.       TabIndex        =   2
  83.       ToolTipText     =   "Pop up reminder message if files need updated."
  84.       Top             =   960
  85.       Value           =   1  'Checked
  86.       Width           =   3195
  87.    End
  88.    Begin VB.CommandButton cmdCheckFiles 
  89.       Caption         =   "Check Files"
  90.       Height          =   495
  91.       Left            =   1440
  92.       TabIndex        =   3
  93.       Top             =   1380
  94.       Width           =   1515
  95.    End
  96.    Begin VB.TextBox txtNetDir 
  97.       Height          =   315
  98.       Left            =   1428
  99.       TabIndex        =   1
  100.       ToolTipText     =   "Directory with shared/network souce code files"
  101.       Top             =   480
  102.       Width           =   3135
  103.    End
  104.    Begin VB.TextBox txtLocalDir 
  105.       Height          =   315
  106.       Left            =   1440
  107.       TabIndex        =   0
  108.       ToolTipText     =   "Directory with local source code files"
  109.       Top             =   48
  110.       Width           =   3135
  111.    End
  112.    Begin VB.CommandButton cmdUpdateFiles 
  113.       Caption         =   "Update Files"
  114.       Height          =   495
  115.       Left            =   3060
  116.       TabIndex        =   4
  117.       Top             =   1380
  118.       Width           =   1515
  119.    End
  120. Attribute VB_Name = "frmCheckInOut"
  121. Attribute VB_GlobalNameSpace = False
  122. Attribute VB_Creatable = False
  123. Attribute VB_PredeclaredId = True
  124. Attribute VB_Exposed = False
  125. Option Explicit
  126. 'API's for selecting a windows directory
  127. Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
  128. Private Declare Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long
  129. Private Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal pv As Long)
  130. Private Type BROWSEINFO
  131.    hOwner           As Long
  132.    pidlRoot         As Long
  133.    pszDisplayName   As String
  134.    lpszTitle        As String
  135.    ulFlags          As Long
  136.    lpfn             As Long
  137.    lParam           As Long
  138.    iImage           As Long
  139. End Type
  140. Private Const BIF_RETURNONLYFSDIRS = &H1
  141. 'API to get Window's logon user name
  142. Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
  143. 'API to set order/positon of window
  144. Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
  145. Private Const SWP_NOMOVE = 2
  146. Private Const SWP_NOSIZE = 1
  147. Private Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE
  148. Private Const HWND_TOPMOST = -1
  149. Private Const HWND_NOTOPMOST = -2
  150. 'variables suffix meanings:
  151. '$ = string
  152. '% = integer
  153. Public User$
  154. Public Minutes%
  155. Public ChkLstFileDir$
  156. Public Extension$
  157. Public blnIgnoreExt As Boolean
  158. Dim CheckTime As Date
  159. Dim LocalMsg$
  160. Dim NetMsg$
  161. Public ConflictMsg$
  162. Dim OutFileNames() As String
  163. Dim OutFileDates() As Date
  164. Dim OutFileSizes() As Long
  165. Dim NetFileNames() As String
  166. Dim NetFileDates() As Date
  167. Dim NetFileSizes() As Long
  168. Dim LocalFileNames() As String
  169. Dim LocalFileDates() As Date
  170. Dim LocalFileSizes() As Long
  171. Dim NewLocalFiles() As String
  172. Dim NewNetFiles() As String
  173. Dim ConflictFileNames() As String
  174. Private Sub chkAutoCheck_Click()
  175.     If chkAutoCheck.Value = 1 Then
  176.         Timer.Enabled = True
  177.     Else
  178.         Timer.Enabled = False
  179.     End If
  180. End Sub
  181. Private Sub cmdCheckFiles_Click()
  182.     If BuildNetArray Then 'quit if error
  183.         If BuildLocalArray Then 'quit if error
  184.             If Not CheckFiles Then
  185.                 MsgBox "Files on local and network are in-sync."
  186.             End If
  187.         End If
  188.     End If
  189.     CheckTime = Now
  190. End Sub
  191. Private Sub cmdResolve_Click()
  192.     frmConflicts.Left = Me.Left
  193.     frmConflicts.Top = Me.Top
  194.     frmConflicts.Show
  195.     Me.Hide
  196. End Sub
  197. Private Sub cmdUpdateFiles_Click()
  198.     MousePointer = vbHourglass
  199.     On Error GoTo NetDirError
  200.     If Dir$(GetUserListFileDir) = "" And txtNetDir <> "" Then
  201.         On Error GoTo 0
  202.         BuildCheckOutList  'rebuild new list
  203.     End If
  204.     On Error GoTo 0
  205.     If UBound(OutFileNames) = 0 Then
  206.         Call BuildOutArray 'load check out files list
  207.     End If
  208.     If BuildNetArray Then 'quit if error
  209.         If BuildLocalArray Then 'quit if error
  210.             If SyncNetAndLocalFiles Then 'quit if error
  211.                 Call ReBuildCheckOutList
  212.             End If
  213.         End If
  214.     End If
  215.     MousePointer = vbDefault
  216.     Exit Sub
  217. NetDirError:
  218.     MousePointer = vbDefault
  219.     MsgBox "Invalid network directory: " & txtNetDir
  220. End Sub
  221. Private Sub BuildCheckOutList() 'returns true if no error
  222.     Dim f%, i%, j%
  223.     If BuildNetArray Then 'quit if error
  224.         If BuildLocalArray Then 'quit if error
  225.             f% = FreeFile
  226.             Open GetUserListFileDir For Output As f%
  227.             For i% = 1 To UBound(LocalFileNames)
  228.                 For j% = 1 To UBound(NetFileNames)
  229.                     If LocalFileNames(i%) = NetFileNames(j%) Then
  230.                         If LocalFileDates(i%) = NetFileDates(j%) And LocalFileSizes(i%) = NetFileSizes(j%) Then 'files are different
  231.                             Print #f%, LocalFileNames(i%) & vbTab & Format$(LocalFileDates(i%), "mm/dd/yyyy hh:nn:ss") & vbTab & LocalFileSizes(i%)
  232.                         End If
  233.                         Exit For
  234.                     End If
  235.                 Next j%
  236.             Next i%
  237.             Close f%
  238.         End If
  239.     End If
  240. End Sub
  241. Private Sub ReBuildCheckOutList()
  242.     Dim f%, k%
  243.     f% = FreeFile
  244.     Open GetUserListFileDir For Output As f%
  245.     For k% = 1 To UBound(OutFileNames)
  246.         Print #f%, OutFileNames(k%) & vbTab & Format$(OutFileDates(k%), "mm/dd/yyyy hh:nn:ss") & vbTab & OutFileSizes(k%)
  247.     Next k%
  248.     Close f%
  249. End Sub
  250. Private Function BuildOutArray() As Boolean 'returns true if no error
  251.     Dim f%, InLine$
  252.     'reads checkout list file to arrays
  253.     BuildOutArray = False
  254.     If txtNetDir = "" Then Exit Function
  255.     If Dir$(GetUserListFileDir) = "" Then
  256.         MsgBox "Error: could not find file" & GetUserListFileDir & "!  You must check out code first."
  257.         Exit Function
  258.     End If
  259.     f% = FreeFile
  260.     Open GetUserListFileDir For Input As f%
  261.     While Not EOF(f%)
  262.         Line Input #f%, InLine$
  263.         If Trim$(InLine$) <> "" Then
  264.             ReDim Preserve OutFileNames(UBound(OutFileNames) + 1) As String
  265.             ReDim Preserve OutFileDates(UBound(OutFileDates) + 1) As Date
  266.             ReDim Preserve OutFileSizes(UBound(OutFileSizes) + 1) As Long
  267.             OutFileNames(UBound(OutFileNames)) = Left$(InLine$, InStr(InLine$, vbTab) - 1)
  268.             InLine$ = Mid$(InLine$, InStr(InLine$, vbTab) + 1)
  269.             OutFileDates(UBound(OutFileDates)) = Left$(InLine$, InStr(InLine$, vbTab) - 1)
  270.             InLine$ = Mid$(InLine$, InStr(InLine$, vbTab) + 1)
  271.             OutFileSizes(UBound(OutFileSizes)) = InLine$
  272.             BuildOutArray = True 'true if found something
  273.         End If
  274.     Wend
  275.     Close f%
  276. End Function
  277. Private Function BuildNetArray() As Boolean 'returns true if no error
  278.     Dim FileName$
  279.     ReDim NetFileNames(0) As String
  280.     ReDim NetFileDates(0) As Date
  281.     ReDim NetFileSizes(0) As Long
  282.     If txtNetDir = "" Then
  283.         BuildNetArray = False
  284.         Exit Function
  285.     End If
  286.     BuildNetArray = True
  287.     If Right(txtNetDir, 1) <> "\" Then
  288.         txtNetDir = txtNetDir & "\"
  289.     End If
  290.     On Error GoTo NetDirError
  291.     FileName$ = Dir$(txtNetDir & "*.*")
  292.     On Error GoTo 0
  293.     If FileName$ = "" Then
  294.         BuildNetArray = False
  295.         MsgBox "Error: no files found in " & txtNetDir
  296.         Exit Function
  297.     End If
  298.     While FileName$ <> ""
  299.         ReDim Preserve NetFileNames(UBound(NetFileNames) + 1) As String
  300.         ReDim Preserve NetFileDates(UBound(NetFileDates) + 1) As Date
  301.         ReDim Preserve NetFileSizes(UBound(NetFileSizes) + 1) As Long
  302.         NetFileNames(UBound(NetFileNames)) = FileName$
  303.         NetFileDates(UBound(NetFileDates)) = FileDateTime(txtNetDir & FileName$)
  304.         NetFileSizes(UBound(NetFileSizes)) = FileLen(txtNetDir & FileName$)
  305.         FileName$ = Dir$
  306.     Wend
  307.     Exit Function
  308. NetDirError:
  309.     MsgBox "Invalid network directory: " & txtNetDir
  310.     BuildNetArray = False
  311. End Function
  312. Private Function BuildLocalArray() As Boolean 'returns true if no error
  313.     Dim FileName$
  314.     ReDim LocalFileNames(0) As String
  315.     ReDim LocalFileDates(0) As Date
  316.     ReDim LocalFileSizes(0) As Long
  317.     If txtLocalDir = "" Then
  318.         BuildLocalArray = False
  319.         Exit Function
  320.     End If
  321.     BuildLocalArray = True
  322.     If Right(txtLocalDir, 1) <> "\" Then
  323.         txtLocalDir = txtLocalDir & "\"
  324.     End If
  325.     FileName$ = Dir$(txtLocalDir & "*.*")
  326.     If FileName$ = "" Then
  327.         If MsgBox("Error: no files found in '" & txtLocalDir & "'. Continue anyhow?", vbYesNo + vbDefaultButton2 + vbExclamation) = vbNo Then
  328.             BuildLocalArray = False
  329.             Exit Function
  330.         End If
  331.     End If
  332.     While FileName$ <> ""
  333.         ReDim Preserve LocalFileNames(UBound(LocalFileNames) + 1) As String
  334.         ReDim Preserve LocalFileDates(UBound(LocalFileDates) + 1) As Date
  335.         ReDim Preserve LocalFileSizes(UBound(LocalFileSizes) + 1) As Long
  336.         LocalFileNames(UBound(LocalFileNames)) = FileName$
  337.         LocalFileDates(UBound(LocalFileDates)) = FileDateTime(txtLocalDir & FileName$)
  338.         LocalFileSizes(UBound(LocalFileSizes)) = FileLen(txtLocalDir & FileName$)
  339.         FileName$ = Dir$
  340.     Wend
  341. End Function
  342. Private Function SyncNetAndLocalFiles() As Boolean 'returns true if copied ok
  343.     Dim i%, j%, k%
  344.     SyncNetAndLocalFiles = False
  345.     Call SetVariables
  346.     If NetMsg$ <> "" Then
  347.         NetMsg$ = "The following new network files will be copied local:" & vbCrLf & NetMsg$
  348.     End If
  349.     If LocalMsg$ <> "" Then
  350.         LocalMsg$ = "The following local files will be copied to the network:" & vbCrLf & LocalMsg$
  351.     End If
  352.     If LocalMsg$ = "" And NetMsg$ = "" And ConflictMsg$ = "" Then
  353.         MsgBox "No files need to be copied."
  354.         SyncNetAndLocalFiles = True
  355.     ElseIf LocalMsg$ = "" And NetMsg$ = "" And ConflictMsg$ <> "" Then
  356.         MsgBox ConflictMsg$ & "No files could be copied."
  357.     Else
  358.         If ConflictMsg$ <> "" Then
  359.             MsgBox ConflictMsg$ & "Other files can still be copied."
  360.         End If
  361.         If NetMsg$ <> "" Then
  362.             If MsgBox(NetMsg$, vbOKCancel, "Copy files to local drive?") = vbOK Then
  363.                 MsgBox "Remember to close the project from the source code editor first."
  364.                 For i% = 1 To UBound(NewNetFiles)
  365.                     On Error Resume Next
  366.                     FileCopy txtNetDir & NewNetFiles(i%), txtLocalDir & NewNetFiles(i%)
  367.                     If Err <> 0 Then
  368.                         MsgBox "Error: Could not copy/replace file " & NewNetFiles(i%)
  369.                     Else
  370.                         For j% = 1 To UBound(NetFileNames)
  371.                             If NewNetFiles(i%) = NetFileNames(j%) Then
  372.                                 For k% = 1 To UBound(OutFileNames)
  373.                                     If NetFileNames(j%) = OutFileNames(k%) Then
  374.                                         OutFileDates(k%) = NetFileDates(j%)
  375.                                         OutFileSizes(k%) = NetFileSizes(j%)
  376.                                         k% = k% + 1
  377.                                         Exit For
  378.                                     End If
  379.                                 Next k%
  380.                                 If NetFileNames(j%) <> OutFileNames(k% - 1) Then
  381.                                     ReDim Preserve OutFileNames(UBound(OutFileNames) + 1) As String
  382.                                     ReDim Preserve OutFileDates(UBound(OutFileDates) + 1) As Date
  383.                                     ReDim Preserve OutFileSizes(UBound(OutFileSizes) + 1) As Long
  384.                                     OutFileNames(UBound(OutFileNames)) = NetFileNames(j%)
  385.                                     OutFileDates(UBound(OutFileDates)) = NetFileDates(j%)
  386.                                     OutFileSizes(UBound(OutFileSizes)) = NetFileSizes(j%)
  387.                                 End If
  388.                                 Exit For
  389.                             End If
  390.                         Next j%
  391.                     End If
  392.                     On Error GoTo 0
  393.                 Next i%
  394.             End If
  395.         End If
  396.         If LocalMsg$ <> "" Then
  397.             If MsgBox(LocalMsg$, vbOKCancel, "Copy files to network?") = vbOK Then
  398.                 For i% = 1 To UBound(NewLocalFiles)
  399.                     On Error Resume Next
  400.                     FileCopy txtLocalDir & NewLocalFiles(i%), txtNetDir & NewLocalFiles(i%)
  401.                     If Err <> 0 Then
  402.                         MsgBox "Error: Could not copy/replace file " & NewLocalFiles(i%)
  403.                     Else
  404.                         For j% = 1 To UBound(LocalFileNames)
  405.                             If NewLocalFiles(i%) = LocalFileNames(j%) Then
  406.                                 For k% = 1 To UBound(OutFileNames)
  407.                                     If LocalFileNames(j%) = OutFileNames(k%) Then
  408.                                         OutFileDates(k%) = LocalFileDates(j%)
  409.                                         OutFileSizes(k%) = LocalFileSizes(j%)
  410.                                         k% = k% + 1
  411.                                         Exit For
  412.                                     End If
  413.                                 Next k%
  414.                                 If LocalFileNames(j%) <> OutFileNames(k% - 1) Then
  415.                                     ReDim Preserve OutFileNames(UBound(OutFileNames) + 1) As String
  416.                                     ReDim Preserve OutFileDates(UBound(OutFileDates) + 1) As Date
  417.                                     ReDim Preserve OutFileSizes(UBound(OutFileSizes) + 1) As Long
  418.                                     OutFileNames(UBound(OutFileNames)) = LocalFileNames(j%)
  419.                                     OutFileDates(UBound(OutFileDates)) = LocalFileDates(j%)
  420.                                     OutFileSizes(UBound(OutFileSizes)) = LocalFileSizes(j%)
  421.                                 End If
  422.                                 Exit For
  423.                             End If
  424.                         Next j%
  425.                     End If
  426.                     On Error GoTo 0
  427.                 Next i%
  428.             End If
  429.         End If
  430.         SyncNetAndLocalFiles = True
  431.     End If
  432. End Function
  433. Private Function CheckFiles() As Boolean 'returns true if copied ok
  434.     CheckFiles = False
  435.     Call SetVariables
  436.     If NetMsg$ <> "" Then
  437.         NetMsg$ = "New files on the network:" & vbCrLf & NetMsg$ & vbCrLf
  438.     End If
  439.     If LocalMsg$ <> "" Then
  440.         LocalMsg$ = "New files local files:" & vbCrLf & LocalMsg$
  441.     End If
  442.     If NetMsg$ <> "" Or LocalMsg$ <> "" Or ConflictMsg$ <> "" Then
  443.         CheckFiles = True
  444.         Beep
  445.         Call OnTopYes(Me.hwnd)
  446.         MsgBox ConflictMsg$ & NetMsg$ & LocalMsg$
  447.         Call OnTopNo(Me.hwnd)
  448.     End If
  449. End Function
  450. Private Sub FindNewLocalFiles()
  451.     Dim i%, j%, k%
  452.     ReDim NewLocalFiles(0) As String
  453.     ReDim ConflictFileNames(0) As String
  454.     Dim foundConflict As Boolean
  455.     Dim found As Boolean
  456.     For i% = 1 To UBound(LocalFileNames)
  457.         found = False
  458.         For j% = 1 To UBound(NetFileNames)
  459.             If LocalFileNames(i%) = NetFileNames(j%) Then
  460.                 If LocalFileDates(i%) <> NetFileDates(j%) Or LocalFileSizes(i%) <> NetFileSizes(j%) Then 'files are different
  461.                     If LocalFileDates(i%) > NetFileDates(j%) Then 'local file is newer
  462.                         foundConflict = True
  463.                         For k% = 1 To UBound(OutFileNames)
  464.                             If NetFileNames(j%) = OutFileNames(k%) Then
  465.                                 foundConflict = False
  466.                                 If NetFileDates(j%) = OutFileDates(k%) And NetFileSizes(j%) = OutFileSizes(k%) Then
  467.                                     ReDim Preserve NewLocalFiles(UBound(NewLocalFiles) + 1) As String
  468.                                     NewLocalFiles(UBound(NewLocalFiles)) = LocalFileNames(i%)
  469.                                 Else
  470.                                     ReDim Preserve ConflictFileNames(UBound(ConflictFileNames) + 1) As String
  471.                                     ConflictFileNames(UBound(ConflictFileNames)) = LocalFileNames(i%)
  472.                                 End If
  473.                                 Exit For
  474.                             End If
  475.                         Next k%
  476.                         If foundConflict Then 'catch confict if never checked out
  477.                             ReDim Preserve ConflictFileNames(UBound(ConflictFileNames) + 1) As String
  478.                             ConflictFileNames(UBound(ConflictFileNames)) = LocalFileNames(i%)
  479.                         End If
  480.                     End If
  481.                 End If
  482.                 found = True
  483.                 Exit For
  484.             End If
  485.         Next j%
  486.         If found = False Then 'new, doesn't exist on net
  487.             ReDim Preserve NewLocalFiles(UBound(NewLocalFiles) + 1) As String
  488.             NewLocalFiles(UBound(NewLocalFiles)) = LocalFileNames(i%)
  489.         End If
  490.     Next i%
  491. End Sub
  492. Private Sub FindNewNetFiles()
  493.     Dim i%, j%, k%
  494.     ReDim NewNetFiles(0) As String
  495.     ReDim ConflictFileNames(0) As String
  496.     Dim found As Boolean
  497.     Dim foundConflict As Boolean
  498.     For i% = 1 To UBound(NetFileNames)
  499.         found = False
  500.         For j% = 1 To UBound(LocalFileNames)
  501.             If NetFileNames(i%) = LocalFileNames(j%) Then
  502.                 If NetFileDates(i%) <> LocalFileDates(j%) Or NetFileSizes(i%) <> LocalFileSizes(j%) Then 'files are different
  503.                     If NetFileDates(i%) > LocalFileDates(j%) Then
  504.                         foundConflict = True
  505.                         For k% = 1 To UBound(OutFileNames)
  506.                             If LocalFileNames(j%) = OutFileNames(k%) Then
  507.                                 foundConflict = False
  508.                                 If LocalFileDates(j%) = OutFileDates(k%) And LocalFileSizes(j%) = OutFileSizes(k%) Then
  509.                                     ReDim Preserve NewNetFiles(UBound(NewNetFiles) + 1) As String
  510.                                     NewNetFiles(UBound(NewNetFiles)) = NetFileNames(i%)
  511.                                 Else
  512.                                     ReDim Preserve ConflictFileNames(UBound(ConflictFileNames) + 1) As String
  513.                                     ConflictFileNames(UBound(ConflictFileNames)) = NetFileNames(i%)
  514.                                 End If
  515.                                 Exit For
  516.                             End If
  517.                         Next k%
  518.                         If foundConflict Then 'catch confict if never checked out
  519.                             ReDim Preserve ConflictFileNames(UBound(ConflictFileNames) + 1) As String
  520.                             ConflictFileNames(UBound(ConflictFileNames)) = NetFileNames(i%)
  521.                         End If
  522.                     End If
  523.                 End If
  524.                 found = True
  525.                 Exit For
  526.             End If
  527.         Next j%
  528.         If found = False Then 'new, doesn't exist on net
  529.             ReDim Preserve NewNetFiles(UBound(NewNetFiles) + 1) As String
  530.             NewNetFiles(UBound(NewNetFiles)) = NetFileNames(i%)
  531.         End If
  532.     Next i%
  533. End Sub
  534. Private Sub SetVariables()
  535.     Dim OneExtension$, i%, start%
  536.     LocalMsg$ = ""
  537.     NetMsg$ = ""
  538.     ConflictMsg$ = ""
  539.     Call FindNewLocalFiles
  540.     For i% = 1 To UBound(NewLocalFiles)
  541.         LocalMsg$ = LocalMsg$ & NewLocalFiles(i%) & vbCrLf
  542.     Next i%
  543.     For i% = 1 To UBound(ConflictFileNames)
  544.         If blnIgnoreExt = False Or Extension$ = "" Then
  545.             ConflictMsg$ = ConflictMsg$ & ConflictFileNames(i%) & vbCrLf
  546.         Else
  547.             start% = 1
  548.             Do While InStr(start%, Extension$ & ",", ",") > 0 And start% < Len(Extension$)
  549.                 OneExtension$ = Mid$(Extension$, start%, InStr(start%, Extension$ & ",", ",") - 1)
  550.                 start% = InStr(start%, Extension$ & ",", ",") + 1
  551.                 If OneExtension$ = Right$(ConflictFileNames(i%), Len(OneExtension$)) Then
  552.                     start% = -1
  553.                     Exit Do
  554.                 End If
  555.             Loop
  556.             If start% <> -1 Then
  557.                 ConflictMsg$ = ConflictMsg$ & ConflictFileNames(i%) & vbCrLf
  558.             End If
  559.         End If
  560.     Next i%
  561.     Call FindNewNetFiles
  562.     For i% = 1 To UBound(NewNetFiles)
  563.         NetMsg$ = NetMsg$ & NewNetFiles(i%) & vbCrLf
  564.     Next i%
  565.     For i% = 1 To UBound(ConflictFileNames)
  566.         If blnIgnoreExt = False Or Extension$ = "" Then
  567.             ConflictMsg$ = ConflictMsg$ & ConflictFileNames(i%) & vbCrLf
  568.         Else
  569.             start% = 1
  570.             Do While InStr(start%, Extension$ & ",", ",") > 0 And start% < Len(Extension$)
  571.                 OneExtension$ = Mid$(Extension$, start%, InStr(start%, Extension$ & ",", ",") - 1)
  572.                 start% = InStr(start%, Extension$ & ",", ",") + 1
  573.                 If OneExtension$ = Right$(ConflictFileNames(i%), Len(OneExtension$)) Then
  574.                     start% = -1
  575.                     Exit Do
  576.                 End If
  577.             Loop
  578.             If start% <> -1 Then
  579.                 ConflictMsg$ = ConflictMsg$ & ConflictFileNames(i%) & vbCrLf
  580.             End If
  581.         End If
  582.     Next i%
  583.     If ConflictMsg$ <> "" Then
  584.         ConflictMsg$ = "Conflicts: Files changed on network!:" & vbCrLf & ConflictMsg$ & vbCrLf
  585.     End If
  586. End Sub
  587. Private Sub cmdHelp_Click()
  588.     frmHelp.Left = Me.Left
  589.     frmHelp.Top = Me.Top
  590.     frmHelp.Show
  591.     Me.Hide
  592. End Sub
  593. Private Sub cmdLocalDir_Click()
  594.     Dim tmpDir$
  595.     tmpDir$ = GetDirectory
  596.     If tmpDir$ <> "" Then
  597.         txtLocalDir = tmpDir$ & "\"
  598.     End If
  599. End Sub
  600. Private Sub cmdMessage_Click()
  601.     frmNetSend.Left = Me.Left
  602.     frmNetSend.Top = Me.Top
  603.     frmNetSend.Show
  604.     Me.Hide
  605. End Sub
  606. Private Sub cmdNetDir_Click()
  607.     Dim tmpDir$
  608.     tmpDir$ = GetDirectory
  609.     If tmpDir$ <> "" Then
  610.         txtNetDir = tmpDir$ & "\"
  611.     End If
  612. End Sub
  613. Private Sub cmdOptions_Click()
  614.     frmOptions.Left = Me.Left
  615.     frmOptions.Top = Me.Top
  616.     frmOptions.Show
  617.     Me.Hide
  618. End Sub
  619. Private Sub Form_Load()
  620.     If App.PrevInstance Then End
  621.     Me.Left = GetSetting(App.EXEName, "Window", "X", 0)
  622.     Me.Top = GetSetting(App.EXEName, "Window", "Y", 0)
  623.     txtNetDir = GetSetting(App.EXEName, "Paths", "Network", txtNetDir)
  624.     txtLocalDir = GetSetting(App.EXEName, "Paths", "Local", txtLocalDir)
  625.     chkAutoCheck = GetSetting(App.EXEName, "Settings", "AutoCheck", chkAutoCheck)
  626.     Minutes% = GetSetting(App.EXEName, "Settings", "CheckMinutes", "15")
  627.     ChkLstFileDir$ = GetSetting(App.EXEName, "Settings", "CheckListFileDir", "<NetDir>\..")
  628.     blnIgnoreExt = GetSetting(App.EXEName, "Settings", "IgnoreExt", True)
  629.     Extension$ = GetSetting(App.EXEName, "Settings", "Extension", ".vbw")
  630.     If GetSetting(App.EXEName, "Paths", "Local") = "" Then
  631.         frmHelp.cmbTopic = "Initial Configuration:"
  632.         Call cmdHelp_Click
  633.     End If
  634.     If Right(txtNetDir, 1) <> "\" And txtNetDir <> "" Then
  635.         txtNetDir = txtNetDir & "\"
  636.     End If
  637.     '----------------------------------
  638.     ' find latest source code directory
  639.     '----------------------------------
  640.     'HighVer$ = "0.0"
  641.     'DirName$ = Dir$(txtNetDir & "Version*", vbDirectory)
  642.     'If DirName$ = "" Then
  643.     '    Exit Sub
  644.     'End If
  645.     'While DirName$ <> ""
  646.     '    If Val(Mid$(HighVer$, InStr(HighVer$, ".") - 1)) < Val(Mid$(DirName$, InStr(DirName$, ".") - 1)) Then
  647.     '        HighVer$ = DirName$
  648.     '    End If
  649.     '    DirName$ = Dir$
  650.     'Wend
  651.     'If HighVer$ <> "0.0" Then
  652.     '    txtNetDir = txtNetDir & HighVer$ & "\"
  653.     'End If
  654.     '----------------------------------
  655.     Dim BuffSize As Long 'get Windows user name
  656.     BuffSize = 199
  657.     User$ = String$(200, 0)
  658.     If GetUserName(User$, BuffSize) = 0 Then
  659.         MsgBox "Error getting username."
  660.     Else
  661.         User$ = Left$(User$, InStr(User$, Chr$(0)) - 1)
  662.     End If
  663.     ReDim OutFileNames(0) As String
  664.     ReDim OutFileDates(0) As Date
  665.     ReDim OutFileSizes(0) As Long
  666.     On Error GoTo NetDirError
  667.     If Dir$(GetUserListFileDir) = "" And txtNetDir <> "" Then
  668.         On Error GoTo 0
  669.         BuildCheckOutList  'rebuild new list
  670.     End If
  671.     On Error GoTo 0
  672.     If txtNetDir <> "" Then
  673.         Call BuildOutArray 'load check out files list
  674.     End If
  675.     CheckTime = DateAdd("n", -1 * (Minutes% + 1), Now)
  676.     Call Timer_Timer
  677.     Exit Sub
  678. NetDirError:
  679.     MsgBox "Invalid network directory: " & txtNetDir
  680.     CheckTime = Now
  681.     On Error GoTo 0
  682. End Sub
  683. Private Sub Form_Unload(Cancel As Integer)
  684.     SaveSetting App.EXEName, "Window", "X", Me.Left
  685.     SaveSetting App.EXEName, "Window", "Y", Me.Top
  686.     SaveSetting App.EXEName, "Paths", "Network", txtNetDir
  687.     SaveSetting App.EXEName, "Paths", "Local", txtLocalDir
  688.     SaveSetting App.EXEName, "Settings", "AutoCheck", chkAutoCheck
  689.     SaveSetting App.EXEName, "Settings", "CheckMinutes", Minutes%
  690.     SaveSetting App.EXEName, "Settings", "CheckListFileDir", ChkLstFileDir$
  691.     SaveSetting App.EXEName, "Settings", "IgnoreExt", blnIgnoreExt
  692.     SaveSetting App.EXEName, "Settings", "Extension", Extension$
  693. End Sub
  694. Private Sub Timer_Timer()
  695.     Dim OtherUserIn As Date
  696.     Dim OtherUserOut As Date
  697.     If DateAdd("n", Minutes%, CheckTime) < Now Then
  698.         'check for updated files
  699.         CheckTime = Now
  700.         If BuildNetArray Then 'quit if error
  701.             If BuildLocalArray Then 'quit if error
  702.                 If Not CheckFiles Then
  703.                     'no new files, ignore
  704.                 End If
  705.             End If
  706.         End If
  707.     End If
  708.     Exit Sub
  709. End Sub
  710. Private Sub OnTopYes(WinHandle As Long)
  711.     Call SetWindowPos(WinHandle, HWND_TOPMOST, 0, 0, 0, 0, FLAGS)
  712. End Sub
  713. Private Sub OnTopNo(WinHandle As Long)
  714.     Call SetWindowPos(WinHandle, HWND_NOTOPMOST, 0, 0, 0, 0, FLAGS)
  715. End Sub
  716. Public Function GetDirectory() As String
  717.     Dim bi As BROWSEINFO
  718.     Dim pidl As Long
  719.     Dim path$, pos%
  720.     bi.hOwner = Me.hwnd
  721.     bi.pidlRoot = 0&
  722.     bi.lpszTitle = "Select directory..."
  723.     bi.ulFlags = BIF_RETURNONLYFSDIRS
  724.     pidl = SHBrowseForFolder(bi)
  725.     path = Space$(256)
  726.     If SHGetPathFromIDList(ByVal pidl, ByVal path) Then
  727.        pos = InStr(path, Chr$(0))
  728.        GetDirectory = Left(path, pos - 1)
  729.     End If
  730.     Call CoTaskMemFree(pidl)
  731. End Function
  732. Public Function GetUserListFileDir(Optional strUser$ = "") As String
  733.     If strUser$ = "" Then
  734.         strUser$ = User$
  735.     End If
  736.     Select Case ChkLstFileDir$
  737.     Case "<NetDir>\.."
  738.         GetUserListFileDir = txtNetDir & "..\checkout_" & strUser$ & ".lst"
  739.     Case "<AppDir>"
  740.         GetUserListFileDir = App.path & "\checkout_" & strUser$ & ".lst"
  741.     Case Else
  742.         GetUserListFileDir = ChkLstFileDir$ & "checkout_" & strUser$ & ".lst"
  743.     End Select
  744. End Function
  745.